package com.test.pm;

import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.*;


public class PMTestFrame01 extends JFrame {

	private static final long serialVersionUID = 1L;
	private final int WIDTH = 10;
	private final int HEIGHT = 5;


	public PMTestFrame01(){
		super();
		
		initializeComponents();
		setVisible(true);
		setSize(new Dimension(400,400));
	}
	
	private void initializeComponents(){
		//this.add(getScrollPane(), BorderLayout.CENTER);
		try {
			this.add(getImagePane(), BorderLayout.CENTER);
		} catch (MalformedURLException e) {
			// T ODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	private JPanel getImagePane() throws MalformedURLException {
		JPanel pane = new JPanel();
		JLabel label = new JLabel(new ImageIcon("img/p0.bmp"));
		pane.add(label);
		return pane;
	}

	private JPanel getScrollPane() {
		JPanel scrollPanel = new JPanel(new BorderLayout());
		
		JScrollPane scroll = new JScrollPane(getMainGridPanel(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPanel.add(scroll, BorderLayout.CENTER);
		
		return scrollPanel;
	}
	//X XX sid = 2009130904

	private JPanel getMainGridPanel() {
		JPanel panel = new JPanel(new GridLayout(HEIGHT,WIDTH,0,0));
		
		for(int row=0; row < HEIGHT; row++)
			for(int col=0; col < WIDTH; col++)
			{
				panel.add(getTile(row, col));
			}
		
		JPanel flowPanel = new JPanel();//FlowLayout
		flowPanel.add(panel);
		
		/*System.out.println(MediaTracker.ABORTED);
		System.out.println(MediaTracker.COMPLETE);
		System.out.println(MediaTracker.ERRORED);
		System.out.println(MediaTracker.LOADING);
		System.out.println();*/
		
		return flowPanel;
	}

	private Component getTile(int row, int col) {
		int tileNum = (int)(Math.random()*16);
		String address = "img/p" + tileNum + ".bmp";
		ImageIcon image = new ImageIcon(address);
		System.out.println(address);
		JLabel button = new JLabel(image);
		
		//button.setIcon(image);
		
		return button;
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable(){
			public void run()
			{
				new PMTestFrame01();
			}
		});
	}

}
